package com.droidlogic.mboxlauncher;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class HoverView extends RelativeLayout {
    private ImageView hoverImage_home;
    private ImageView hoverImage_second;
    private Context mContext;
    private TextView textBottom;
    private TextView textTop;

    public HoverView(Context context) {
        super(context);
        this.mContext = context;
    }

    public HoverView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initlayout();
    }

    public HoverView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private void initlayout() {
        inflate(this.mContext, R.layout.layout_hover, this);
        this.hoverImage_home = (ImageView) findViewById(R.id.img_hover_home);
        this.hoverImage_second = (ImageView) findViewById(R.id.img_hover_second);
        this.textTop = (TextView) findViewById(R.id.tx_hover_top);
        this.textBottom = (TextView) findViewById(R.id.tx_hover_bottom);
    }

    private void startAnimation() {
        ScaleAnimation shadowAnim = new ScaleAnimation(0.95f, 1.0f, 0.95f, 1.0f, 1, 0.5f, 1, 0.5f);
        shadowAnim.setDuration(70);
        shadowAnim.setStartTime(0);
        shadowAnim.setAnimationListener(new ScaleAnimationListener(this, (ScaleAnimationListener) null));
        startAnimation(shadowAnim);
    }

    public void clear() {
        this.hoverImage_home.setBackgroundDrawable((Drawable) null);
        this.hoverImage_home.setImageDrawable((Drawable) null);
        this.hoverImage_second.setBackgroundDrawable((Drawable) null);
        this.hoverImage_second.setImageDrawable((Drawable) null);
        this.textTop.setText((CharSequence) null);
        this.textBottom.setText((CharSequence) null);
        setOutlineProvider((ViewOutlineProvider) null);
        setElevation(0.0f);
        setViewPosition(this, new Rect(0, 0, 0, 0));
    }

    public void setHover(MyRelativeLayout focusView) {
        Rect imgRect = new Rect();
        float scale = focusView.getScale();
        float elevation = focusView.getElevation();
        final float shadowScale = focusView.getShadowScale();
        focusView.getGlobalVisibleRect(imgRect);
        if (((Launcher) this.mContext).needPreviewFeture()) {
            if (focusView.getType() == 0) {
                ((Launcher) this.mContext).setTvViewElevation(51.0f);
            } else {
                ((Launcher) this.mContext).setTvViewElevation(10.0f);
            }
            if (!(((Launcher) this.mContext).getCurrentScreenMode() == 0 || ((Launcher) this.mContext).getCurrentScreenMode() == 6)) {
                if (((Launcher) this.mContext).tvViewMode != 1) {
                    int i = (imgRect.top + imgRect.bottom) / 2;
                    Launcher launcher = (Launcher) this.mContext;
                    if (i > Launcher.dipToPx(this.mContext, 360.0f)) {
                        ((Launcher) this.mContext).setTvViewPosition(1);
                    }
                }
                if (((Launcher) this.mContext).tvViewMode != 2) {
                    int i2 = (imgRect.top + imgRect.bottom) / 2;
                    Launcher launcher2 = (Launcher) this.mContext;
                    if (i2 <= Launcher.dipToPx(this.mContext, 360.0f)) {
                        ((Launcher) this.mContext).setTvViewPosition(2);
                    }
                }
            }
        }
        int scale_w = (int) (((scale - 1.0f) * ((float) imgRect.width())) / 2.0f);
        int scale_h = (int) (((scale - 1.0f) * ((float) imgRect.height())) / 2.0f);
        setViewPosition(this, new Rect(imgRect.left - scale_w, imgRect.top - scale_h, imgRect.right + scale_w, imgRect.bottom + scale_h));
        setOutlineProvider(new ViewOutlineProvider() {
            @SuppressLint("Range")
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect((int) (((1.0f - shadowScale) * ((float) view.getWidth())) / 2.0f), (int) (((1.0f - shadowScale) * ((float) view.getHeight())) / 2.0f), (int) (((shadowScale + 1.0f) / 2.0f) * ((float) view.getWidth())), (int) (((shadowScale + 1.0f) / 2.0f) * ((float) view.getHeight())), 20.0f);
                outline.setAlpha(200.0f);
            }
        });
        setElevation(elevation);
        setHoverImage(focusView, (ImageView) focusView.getChildAt(0));
        if (focusView.getChildAt(1) instanceof TextView) {
            setHoverText(focusView, ((TextView) focusView.getChildAt(1)).getText().toString());
        } else {
            setHoverText(focusView, (String) null);
        }
        if (focusView.getVisibility() == VISIBLE) {
            startAnimation();
        }
    }

    private void setHoverImage(MyRelativeLayout focusView, ImageView source) {
        if (focusView.getType() != 7) {
            this.hoverImage_home.setBackgroundDrawable(source.getBackground());
            this.hoverImage_home.setImageDrawable(source.getDrawable());
            this.hoverImage_second.setBackgroundDrawable((Drawable) null);
            this.hoverImage_second.setImageDrawable((Drawable) null);
            return;
        }
        this.hoverImage_home.setBackgroundDrawable((Drawable) null);
        this.hoverImage_home.setImageDrawable((Drawable) null);
        this.hoverImage_second.setBackgroundDrawable(source.getBackground());
        this.hoverImage_second.setImageDrawable(source.getDrawable());
    }

    private void setHoverText(MyRelativeLayout focusView, String s) {
        if (focusView.getType() != 7) {
            this.textTop.setText(s);
            this.textBottom.setText((CharSequence) null);
            return;
        }
        this.textTop.setText((CharSequence) null);
        this.textBottom.setText(s);
    }

    public static void setViewPosition(View view, Rect rect) {
        FrameLayout.LayoutParams para = new FrameLayout.LayoutParams(rect.width(), rect.height());
        para.setMargins(rect.left, rect.top, 0, 0);
        view.setLayoutParams(para);
    }

    private class ScaleAnimationListener implements Animation.AnimationListener {
        /* synthetic */ ScaleAnimationListener(HoverView this$02, ScaleAnimationListener scaleAnimationListener) {
            this();
        }

        private ScaleAnimationListener() {
        }

        public void onAnimationStart(Animation animation) {
        }

        public void onAnimationEnd(Animation animation) {
        }

        public void onAnimationRepeat(Animation animation) {
        }
    }
}